<?php
AppCore::using('Dao_Adaptor_Pdo');
/**
 * data adaptor for Sqlite
 * Actually uses PDO...
 * @author bruce.li
 * @implements <iDao_Adaptor_Base>
 */
class Dao_Adaptor_Sqlite extends Dao_Adaptor_Pdo
{
    /**
     * construct the adaptor
     *
     * @param array $options
     *
     * @return void
     */
    public function __construct($options = array())
    {
        if (!isset($options['dbname'])) {
            return $this->_error(null, null, 'Option is invalid');
        }

        // we dont want more than 1 connection to the db...
        $key = md5($options['dbname']);
        $dsn = 'sqlite:' . $options['dbname'];
        if (Util_Reg::get($key) instanceof PDO) {
            $this->_pdo = Util_Reg::get($key);
            return true;
        }

        try {
            Util_Reg::register($key, new PDO($dsn));
            $this->_pdo = Util_Reg::get($key);
        } catch (PDOException $e) {
            // throw our own exception object
            $this->_throw($e);
        }

    }// end __construct


    // quote names
    public function nameQuote($name)
    {
        if (strpos($name, '.') !== false) {
            $name = str_replace('.', '","',  $object->__getTableName());
        }
        return '"' . $name . '"';

    }// end nameQuote

}// end Dao_Adaptor_Sqlite
?>